using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class GamePoolManager
{
	private static Dictionary<string, GamePool> GamePoolDict;

	private static GameObject _poolHolder;

	public static void CreatePool(string iPoolName)
	{
		if (GamePoolDict == null)
		{
			GamePoolDict = new Dictionary<string, GamePool>();
			_poolHolder = new GameObject("GamePoolHolder");
		}
		if (!GamePoolDict.ContainsKey(iPoolName))
		{
			GamePoolDict.Add(iPoolName, new GamePool(_poolHolder, iPoolName));
		}
	}

	public static int AddGameObjectToPool(string iPoolName, GameObject iPrefab, int iCount, GamePoolSettings iGamePoolSettings)
	{
		if (GamePoolDict == null || !GamePoolDict.ContainsKey(iPoolName))
		{
			BCWDebug.LogError("Game pool " + iPoolName + " not found");
			return -1;
		}
		if (iPrefab == null)
		{
			return -1;
		}
		return GamePoolDict[iPoolName].AddGameObjectToPool(iPrefab, iCount, iGamePoolSettings);
	}

	public static GameObject GetGameObjectFromPool(string iPoolName, int iObjectId)
	{
		if (GamePoolDict == null || !GamePoolDict.ContainsKey(iPoolName))
		{
			BCWDebug.LogError("Game pool " + iPoolName + " not found");
			return null;
		}
		return GamePoolDict[iPoolName].GetGameObjectById(iObjectId);
	}

	public static GameObject GetGameObjectFromPool(string iPoolName, GameObject iPrefab)
	{
		if (GamePoolDict == null || !GamePoolDict.ContainsKey(iPoolName))
		{
			BCWDebug.LogError("Game pool " + iPoolName + " not found");
			return null;
		}
		return GamePoolDict[iPoolName].GetGameObjectByPrefab(iPrefab);
	}

	public static void ActivateGameObject(GameObject iGameObject)
	{
		iGameObject.SetActive(true);
		iGameObject.SendMessage("OnPoolActivate", SendMessageOptions.DontRequireReceiver);
	}

	public static void ActivateGameObjectWithParticles(GameObject iGameObject)
	{
		iGameObject.SetActive(true);
		iGameObject.SendMessage("OnPoolActivate", SendMessageOptions.DontRequireReceiver);
		ParticleSystem[] components = iGameObject.GetComponents<ParticleSystem>();
		for (int i = 0; i < components.Length; i++)
		{
			components[i].Stop();
			components[i].Play();
		}
		components = iGameObject.GetComponentsInChildren<ParticleSystem>();
		for (int j = 0; j < components.Length; j++)
		{
			components[j].Stop();
			components[j].Play();
		}
	}

	public static void ReturnGameObjectToPool(GameObject iGameObject)
	{
		if (!(iGameObject == null))
		{
			GamePoolTracker component = iGameObject.GetComponent<GamePoolTracker>();
			if (!(component == null) && component.IsBusy)
			{
				component.GamePoolObject.ReturnGameObject(component);
			}
		}
	}

	public static void RemoveObjectFromPool(string iPoolName, int iObjectId)
	{
		if (GamePoolDict == null || !GamePoolDict.ContainsKey(iPoolName))
		{
			BCWDebug.LogError("Game pool " + iPoolName + " not found for clear");
		}
		else
		{
			GamePoolDict[iPoolName].RemoveGameObjectFromPool(iObjectId);
		}
	}

	public static void ClearPool(string iPoolName)
	{
		if (GamePoolDict == null || !GamePoolDict.ContainsKey(iPoolName))
		{
			BCWDebug.LogError("Game pool " + iPoolName + " not found for clear");
			return;
		}
		GamePoolDict[iPoolName].Clear();
		GamePoolDict.Remove(iPoolName);
	}

	public static void ClearAll()
	{
		int num;
		for (num = 0; num < GamePoolDict.Count; num++)
		{
			ClearPool(GamePoolDict.ElementAt(num).Key);
			num--;
		}
	}
}
